ensure user receiving an encrypted share maintain proper state
authorMatthieu Gallien <matthieu.gallien@nextcloud.com>
Thu, 13 Mar 2025 10:36:10 +0000 (11:36 +0100)
committerMatthieu Gallien <matthieu.gallien@nextcloud.com>
Thu, 13 Mar 2025 11:35:24 +0000 (12:35 +0100)
will make sure the client internal database keeps proper encryption
information

Signed-off-by: Matthieu Gallien <matthieu.gallien@nextcloud.com>
src/libsync/encryptfolderjob.cpp
src/libsync/propagateupload.cpp

index e7740a85b63872afa69dec6ed061f1b880cba875..b78eec7dabf1e254f938e10b6e535a87eafc6111 100644 (file)
@@ -72,6 +72,8 @@ void EncryptFolderJob::slotEncryptionFlagSuccess(const QByteArray &fileId)
     if (!rec.isValid()) {
         if (_propagator && _item) {
             qCWarning(lcEncryptFolderJob) << "No valid record found in local DB for fileId" << fileId << "going to create it now...";
+            _item->_e2eEncryptionStatus = EncryptionStatusEnums::ItemEncryptionStatus::EncryptedMigratedV2_0;
+            _item->_e2eCertificateFingerprint = _account->e2e()->certificateSha256Fingerprint();
             const auto updateResult = _propagator->updateMetadata(*_item.data());
             if (updateResult) {
                 [[maybe_unused]] const auto result = _journal->getFileRecord(currentPath, &rec);
@@ -81,7 +83,7 @@ void EncryptFolderJob::slotEncryptionFlagSuccess(const QByteArray &fileId)
         }
     }
 
-    if (!rec.isE2eEncrypted()) {
+    if (rec.isValid() && !rec.isE2eEncrypted()) {
         rec._e2eEncryptionStatus = SyncJournalFileRecord::EncryptionStatus::Encrypted;
         rec._e2eCertificateFingerprint = _account->e2e()->certificateSha256Fingerprint();
         const auto result = _journal->setFileRecord(rec);
index a38359d9449e47b0dcbaf16475147e80f45e8622..4946f05e98d5065c2783f84a0f383e3bb95fe5bb 100644 (file)
@@ -249,6 +249,8 @@ void PropagateUploadFileCommon::setupEncryptedFile(const QString& path, const QS
 {
     qCDebug(lcPropagateUpload) << "Starting to upload encrypted file" << path << filename << size;
     _uploadingEncrypted = true;
+    _item->_e2eEncryptionStatus = EncryptionStatusEnums::ItemEncryptionStatus::EncryptedMigratedV2_0;
+    Q_ASSERT(_item->isEncrypted());
     _fileToUpload._path = path;
     _fileToUpload._file = filename;
     _fileToUpload._size = size;
@@ -450,6 +452,8 @@ void PropagateUploadFileCommon::slotFolderUnlocked(const QByteArray &folderId, i
 void PropagateUploadFileCommon::slotOnErrorStartFolderUnlock(SyncFileItem::Status status, const QString &errorString)
 {
     if (_uploadingEncrypted) {
+        Q_ASSERT(_item->isEncrypted());
+
         _uploadStatus = { status, errorString };
         connect(_uploadEncryptedHelper, &PropagateUploadEncrypted::folderUnlocked, this, &PropagateUploadFileCommon::slotFolderUnlocked);
         _uploadEncryptedHelper->unlockFolder();
@@ -839,6 +843,8 @@ void PropagateUploadFileCommon::finalize()
     propagator()->_journal->commit("upload file start");
 
     if (_uploadingEncrypted) {
+        Q_ASSERT(_item->isEncrypted());
+
         _uploadStatus = { SyncFileItem::Success, QString() };
         connect(_uploadEncryptedHelper, &PropagateUploadEncrypted::folderUnlocked, this, &PropagateUploadFileCommon::slotFolderUnlocked);
         _uploadEncryptedHelper->unlockFolder();